package com.inspur.cloud.service.dataspace;

import com.inspur.cloud.dao.dataspace.HdfsResourceDao;
import com.inspur.cloud.entity.dataspace.HdfsResourceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
public class HdfsResourceService {
    @Autowired
    private HdfsResourceDao hdfsResourceDao;

    public void save(HdfsResourceEntity hdfsResourceEntity){
        hdfsResourceDao.save(hdfsResourceEntity);
    }
    public void saveAndFlush(HdfsResourceEntity hdfsResourceEntity){
        hdfsResourceDao.saveAndFlush(hdfsResourceEntity);
    }
    public Page<HdfsResourceEntity> findAll(Specification<HdfsResourceEntity> specification , PageRequest pageRequest){
        return hdfsResourceDao.findAll(specification,pageRequest);
    }
    public Optional<HdfsResourceEntity> findById(Integer id){
        return hdfsResourceDao.findById(id);
    }
    public HdfsResourceEntity findHdfsResourceEntityById(Integer id){
        return hdfsResourceDao.findHdfsResourceEntityById(id);

    }
    public HdfsResourceEntity findFirstByUrl(String path){
        return hdfsResourceDao.findFirstByUrl(path);
    }
    public HdfsResourceEntity findFirstByOwner(Integer owner, Integer parentId){
        return hdfsResourceDao.findFirstByOwner(owner,parentId);
    }

    public List<HdfsResourceEntity> findAll() {
        return hdfsResourceDao.findAll();
    }
    public List<HdfsResourceEntity> findByParentId(Integer parentId){
        return hdfsResourceDao.findByParentId(parentId);
    }
    public  List<Integer> findIdByParentId(Integer parentId){
        return hdfsResourceDao.findIdByParentId(parentId);
    }
    @Transactional
    public Integer deleteByParentId(Integer parentId){
        return hdfsResourceDao.deleteByParentId(parentId);
    }
    public List<Integer> findByUrlLike(String url){
        return hdfsResourceDao.findByUrlLike(url);
    }
    public Integer deleteByIdList(List<Integer> idList){
        return hdfsResourceDao.deleteByIdList(idList);
    }
}
